<?php
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/utilities/xajax/xajax_core/xajax.inc.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/gui/presenter/PresenterLogin.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/gui/presenter/PresenterEmail.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/gui/presenter/PresenterCreateNews.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php';
		
	$debug = FirePHP :: getInstance(true);
	$debug -> setEnabled(true);
	
	error_reporting (E_ALL ^ E_NOTICE);
	
	$_SESSION['debug'] = $debug;
	
	$xajax = new xajax(); 
	 
	$xajax -> register(XAJAX_FUNCTION, 'clickAccess');
	$xajax -> register(XAJAX_FUNCTION, 'clickEmail');
	$xajax -> register(XAJAX_FUNCTION, 'selectNews');
	$xajax -> register(XAJAX_FUNCTION, 'showNews');
	 
	$xajax -> processRequest(); 
	 
	$xajax -> configure('javascript URI','../../../utilities/xajax/');
	
	/**
	 * Method to select news
	 */
	function selectNews() {
		$presenterNews = new PresenterCreateNews();
		
		$news = $presenterNews -> selectNews();
		
		$response = new xajaxResponse();
		
		$response -> assign("content", "innerHTML", $news);
		
		return $response;
	}
	
	/**
	 * Method to show single news
	 */
	function showNews($title, $date, $image, $description) {
		$presenterNews = new PresenterCreateNews();
		
		$news = $presenterNews -> showNews($title, $date, $image, $description);
		
		$response = new xajaxResponse();
		
		$response -> assign("content", "innerHTML", $news);
		
		return $response;
	}
	
	function clickAccess($username, $password) {
		$presenterLogin = new PresenterLogin();
		
		$department = $presenterLogin -> clickValidateUser($username, $password);
		
		$response = new xajaxResponse();
		
		if (strcmp($department, "false") == 0)
			$response -> assign("userValidation", "innerHTML", 'Credencial inv&aacute;lida');
		
		else {
			switch ($department) {
			    case 'Gerencia General':
				    $response -> redirect('../start/start.php?username=' . $username . 
						'&department=' . $department);
			    break;
			  
			    case 'Ventas':
				    $response -> redirect('../salesMenuAccess/salesAccess.php?username=' .
						$username . '&department=' . $department);
			    break;
			  
			    case 'Produccion':
				    $response -> redirect
						('../productionMenuAccess/productionAccess.php?username=' . 
						$username . '&department=' . $department);
			    break;
			  
			    case 'Instalacion':
				    $response -> redirect
						('../installationMenuAccess/installationAccess.php?username=' . 
						$username . '&department=' . $department);
			    break;
		  	}
		}
		   	
    	return $response;
	}
	
	// funcion para invocar el presentador para el
	// el envio de correo.
	function clickEmail($email) {
		$presenterEmail = new PresenterEmail();
		$GLOBALS['debug'] -> log($email,"Entro a la funcion email en la vista");
		
		$email = $presenterEmail -> clickSendEmail($email);
		$response = new xajaxResponse();
		
		if (strcmp($email, "false") == 0)
			$response -> assign("email", "innerHTML", 'Email inv&aacute;lido');
		
		else {
		
			$response -> assign("transactionResult", "innerHTML", 
				'<font size="+1" color="#006600">Operaci&oacute;n  exitosa</font>');
		}
		
		$GLOBALS['debug'] -> log($email,"Salio de la funcion email en la vista");
    	
		return $response;
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bienvenido al Sistema Automatizado para la Gesti&oacute;n Empresarial de Recursos - SAGER</title>
<?php 
	$xajax->printJavascript("../../../utilities/xajax/"); 
?>
<link rel="stylesheet" type="text/css" href="../css/styles.css" />
<link rel="stylesheet" type="text/css" href="../css/styles2.css" />
<script src="../jq/jquery-1.4.1.min.js" type="text/javascript"></script>
<!-- include the Tools -->
<script src="http://cdn.jquerytools.org/1.2.5/full/jquery.tools.min.js"></script>
<!-- tooltip styling -->
<link rel="stylesheet" type="text/css" href="http://static.flowplayer.org/tools/css/tooltip-generic.css"/>
<script type="text/javascript">
	function getTime(){
    	currentTime = new Date()
    	hour = currentTime.getHours()
		minute = currentTime.getMinutes()
		second = currentTime.getSeconds()

		str_second = new String (second)
		if (str_second.length == 1)
		   second = "0" + second
	
		str_minute = new String (minute)
		if (str_minute.length == 1)
		   minute = "0" + minute
	
		str_hour = new String (hour)
		if (str_hour.length == 1)
		   hour = "0" + hour
	
		printableHour = hour + " : " + minute + " : " + second
	
		document.form_watch.watch.value = printableHour
	
		setTimeout("getTime()",1000)
	}
		// contactenos
		function contacts() {
		$("#content").load("../global/contacts.php"); 
		};
		// **********************************sedes
		function caracas() {
		$("#content").load("../global/constructions.php"); 
		};

		function valencia() {
		$("#content").load("../global/constructions.php"); 
		};
	
		function maracay() {
		$("#content").load("../global/constructions.php"); 
		};
/////////////////////////////////////JQUERY****//////////////////////////////////////////////////////////	
  $(document).ready(function (){	  
	  //$("#content").load("../news/news.php");
	  //loading menu
	  $("#lateralMenu").load("homeMenu.htm");
	  
	  //funcion para armar el objeto del usuario.
	
	  
	  // initialize tooltip
	  $("#myform :input").tooltip({
		  // tweak the position
		  offset: [-2, 10],
		  // use the "slide" effect
		  effect: 'slide'
		  // add dynamic plugin with optional configuration for bottom edge
	  }).dynamic({ bottom: { direction: 'up', bounce: true } });

	  var triggers = $(".modalInput").overlay({
		  // some mask tweaks suitable for modal dialogs
		  mask: {
			  color: '#ebecff',
			  loadSpeed: 200,
			  opacity: 0.9
		  },
	  	  closeOnClick: false
	  });

	  $("#prompt form").submit(function(e) {

		  // close the overlay
		  triggers.eq(1).overlay().close();

		  // get user input
		  var input = $("input", this).val();

		  // do something with the answer
		  triggers.eq(1).html(input);

		  // do not submit the form
		  return e.preventDefault();
	  });
	  
	  
  	
	  
  });
</script>
</head>



<body onload="getTime()">
	<div id="container">    
    <!---------------------------------- Top bar ----------------------------------------->
    	<div id="topBar">
        	<form name="form_watch">
            	<div id="connectedUser">Bienvenido visitante</div>
                <input type="text" name="watch" size="12" 
                	onfocus="window.document.form_watch.watch.blur()" />
            </form>
        </div>
        
    <!----------------------------------- Header ----------------------------------------->
    	<div id="header">
        	<img src="../images/logo.jpg" width="100%" height="130px" alt="Ductobarra / Busduct" border="0">
        </div>
    
    <!---------------------------------- Lateral menu ----------------------------------------->
        <div id="lateralMenu"></div>
                
   
    <!--------------------------------- Prompt Password --------------------------------------->      	<div class="modal" id="promptPassword">
        	<form  name="myform1" id="myform1">
            	<div align="center"><h2>Recuperaci&oacute;n de clave</h2></div>
                
                <div id="inputs">
                	<table align="center">
                    	<tr> <!-- email -->
                        	<td align="right"><label for="email">Correo electr&oacute;nico</label></td>
                            <td align="left"><input id="email" title="Debe ser una direcci&oacute;n v&aacute;lida"/></td>                            
                        </tr>
                        
                       <tr><!-- proceed -->
                        	<td align="center" colspan="2"><input type="button" id="Enviar" value="Enviar" onclick="xajax_clickEmail(document.myform1.email.value)" /></td>
                        </tr>
                    </table>
                    
                    <div class="cancelRecovery"><img src="../images/cerrar.jpg" width="25px" height="25px" />&nbsp;Presione ESC para cancelar</div>
                </div>
            </form>
      	</div>
        
    <!--------------------------------- Content --------------------------------------->
        <div id="content">
        	<script>
				xajax_selectNews();
			</script>
        </div>
            
    <!--------------------------------- Cuerpo lateral --------------------------------------->
        <div id="cuerpolateral">        
    <!--------------------------------- Login --------------------------------------->
        	<h2 class="cuerpolateral">Inicie sesi&oacute;n</h2>
	        <form name="myform" id="myform">
			<div id="inputs">            
	            <table align="center">
    	        	<tr>
        	        	<td align="right">
            				<!-- username -->
							<div id="label"><label for="username">Usuario</label></div>
                    	 </td>
						<td align="left">
                    		<input id="username" size="10" />
                    	</td>
                	</tr>
                
                	<tr>
						<td align="right">
							<!-- password -->
							<div id="label"><label for="password">Clave</label></div>
                    	</td>
						<td align="left">
							<input id="password" size="10" type="password" />
                    	</td>
              		</tr>
                    
                    <tr>
                    	<td align="center" colspan="2"><div id="userValidation"></div></td>
                    </tr>
                
                	<tr>
                		<td align="center" colspan="2">
                    		<input type="button" id="access" value="Acceder" onclick="xajax_clickAccess(document.myform.username.value, document.myform.password.value)" />
                    	</td>
                	</tr>
                
                	<tr>
                
                    	<td align="center">
                    		<a href="../../../prompt" class="modalInput" rel="#promptPassword">¿Olvid&oacute; su clave?</a>
                   		</td>
                	</tr>
            	</table>
            </div>
			</form>
                        
  <!-------------------------------------- Búsqueda ------------------------------------------->
            <h2 class="cuerpolateral">Buscar</h2>
            <form id="myform">
			<div id="inputs">            	
            	<table align="center">
                   	<tr>
                       	<td align="right">
							<!-- criteria -->
							<div id="label"><label for="criteria">Criterio</label></div>
                    	</td>
						<td align="left">
							<input id="criteria" size="10" type="text" title="Ingrese criterio de b&uacute;squeda" />
                    	</td>
                           
                        <td align="left">
                           	<input type=image src="../images/go.gif" width="25" height="15">
                        </td>
                  	</tr>
                        
                    <tr>
                    	<td align="left" colspan="3">
                           	<div class="radio">
                               	<input type="radio" name="op" value="1">&nbsp;En SAGER&nbsp;
                            </div>
                            <div class="radio">
                          		<input type="radio" name="op" value="2">&nbsp;En toda la web
                            </div>
                        </td>
                  	</tr>
                </table>
            </div>
            </form>        	
    	</div>        
    </div>

  <!-------------------------------------- Footer ------------------------------------------->
    <div id="footer">
    	<p><strong>DUCTOBARRA - Distribuci&oacute;n El&eacute;ctrica Inteligente. RIF J-0373724324</strong></p>
	</div>
</body>
</html>